package com.aistar.service.impl;

import com.aistar.mapper.ProductImagesMapper;
import com.aistar.pojo.ProductImages;
import com.aistar.pojo.ProductImagesExample;
import com.aistar.service.ProductImagesService;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ProductImagesServiceImpl implements ProductImagesService {

    @Autowired
    private ProductImagesMapper productImagesMapper;

    @Override
    public ServerResponse save(ProductImages productImages) {
        return null;
    }

    @Override
    public ServerResponse modifyStatus(ProductImages productImages) {
        return null;
    }

    @Override
    public ServerResponse modify(ProductImages productImages) {
        return null;
    }

    @Override
    public ServerResponse getById(Integer id) {
        return null;
    }

    @Override
    public ServerResponse getAll() {
        return null;
    }


    //查询方法根据商品id来查询商品图片
    @Override
    public ServerResponse getByProductId(Integer productId) {
        ProductImagesExample productImagesExample = new ProductImagesExample();
        productImagesExample.createCriteria().andProductImagesStatusEqualTo(1)
                .andProductIdEqualTo(productId);
        List<ProductImages> productImagesList = productImagesMapper.selectByExample(productImagesExample);
        if (productImagesList !=null && productImagesList.size()>0)
            return ServerResponse.getDataSuccess(productImagesList);
        return ServerResponse.getDataFailed("该商品没有图片");
    }

    @Override
    public ServerResponse getByProductIdTo(Integer productId) {
        ProductImagesExample productImagesExample = new ProductImagesExample();
        productImagesExample.createCriteria().andProductImagesStatusEqualTo(1)
                .andProductIdEqualTo(productId);
        List<ProductImages> productImagesList = productImagesMapper.selectByExample(productImagesExample);
        if (productImagesList !=null && productImagesList.size()>0)
            return ServerResponse.getDataSuccess(productImagesList.get(1));
        return ServerResponse.getDataFailed("该商品没有图片");
    }


}
